PREV='Y'
BUL1=SUBSTR(DTOS(DATE()),5,2)+SUBSTR(DTOS(DATE()),3,2)
DO WHILE .T.
   @ 13,1 CLEA TO 23,78
   SET COLOR TO R+*/N
   STORE SPACE(9) TO VISIT1,VISIT2,VISIT3,VISIT4,VISIT5,VISIT6,VISIT7,VISIT8,VISIT9
   STORE DATE() TO date1,date2,date3,date4,date5,date6,DATE7,DATE8,DATE9
   @ 15,25 SAY "Processing, Please Wait ..."
   set color to bg+/b,w+n
   sele 3
   set exclu off
   use &dr2&fA2 index &dr2&fA2
   GO TOP
   seek kdpat
   IF FOUND()
      DO WHILE PAT_FILCOD=KDPAT .AND. .NOT. EOF()
         buln='2'
         DO PCON120
         SKIP
      ENDDO
   ENDIF
   IF VISIT1=SPACE(9)
      sele 3
      set exclu off
      use &dr2&fA2 index &dr2&FA2
      GO TOP
      SEEK CNAME+CFNAME
      IF FOUND()
         DO WHILE PAT_NAME=CNAME .AND. PAT_F_NAME=CFNAME
            buln='2'
            DO PCON120
            SKIP
         ENDDO
      ENDIF
   ENDIF
   set color to bg+/b,w+/n
   IF VISIT1<>SPACE(9)
         SELE 4
         SET EXCLU OFF
         USE &DR2&FC2 INDEX &DR2&FC2
         SELE 5
         SET EXCLU OFF
         USE &DR2&FD2 INDEX &DR2&FD2
   ELSE
      @ 13,1 CLEA TO 23,78
      @ 18,20 SAY "THERE IS NO VISIT RECORDED FOR THIS PATIENT"
      rankv=space(3)
      do pcon40
      RETURN
   ENDIF
   exit
ENDDO
do pcon13
return
